<?php declare(strict_types=1);
/**
 * @author      xianganyall <xianganyall@gmail.com>
 * @copyright   2023-2025 owner
 **/

namespace Srv\Libs\ConfModel;

final class NetworkConf extends ConfAbstract
{
    public const PREFIX                         = 'NET.';               // 配置前缀[必定点结尾]
    private string $groupName                   = '';                   // 分组名
    protected bool $proxyHttp                   = false;                // 是否启用Http代理
    protected string $proxyHttpHost             = '';                   // Http代理主机
    protected string $proxyHttpPort             = '';                   // Http代理端口
    protected string $proxyHttpUsername         = '';                   // Http代理用户名
    protected string $proxyHttpPassword         = '';                   // Http代理密码
    protected bool $proxySocks5                 = false;                // 是否启用Socks5代理
    protected string $proxySocks5Host           = '';                   // Socks5代理主机
    protected string $proxySocks5Port           = '';                   // Socks5代理端口
    protected string $proxySocks5Username       = '';                   // Socks5代理用户名
    protected string $proxySocks5Password       = '';                   // Socks5代理密码

    /**
     * @param array $confData
     * @param string $groupName
     * __construct
     */
    public function __construct(array $confData, string $groupName)
    {
        $this->init($confData);
        $this->groupName = $groupName;
    }

    /**
     * @return array
     * getProxyParamHttp
     */
    public function getProxyParamHttp():array
    {
        if(!$this->isProxyHttp()) return [];
        return ['PROXY_HTTP_IP' => $this->getProxyHttpHost(), 'PROXY_HTTP_PORT' => $this->getProxyHttpPort(), 'PROXY_HTTP_USER' => $this->getProxyHttpUsername(), 'PROXY_HTTP_PASS' => $this->getProxyHttpPassword()];
    }

    /**
     * @return array
     * getProxyParamSocks5
     */
    public function getProxyParamSocks5():array
    {
        if(!$this->isProxySocks5()) return [];
        return ['PROXY_SOCKS5_IP' => $this->getProxySocks5Host(), 'PROXY_SOCKS5_PORT' => $this->getProxySocks5Port(), 'PROXY_SOCKS5_USER' => $this->getProxySocks5Username(), 'PROXY_SOCKS5_PASS' => $this->getProxySocks5Password()];
    }

    /**
     * @return array
     * getProxyParam
     */
    public function getProxyParam(bool $socks5, bool $http):array
    {
        return array_merge($socks5 ? $this->getProxyParamSocks5() : [], $http ? $this->getProxyParamHttp() : []);
    }

    /**
     * @return string
     */
    public function getGroupName(): string
    {
        return $this->groupName;
    }

    /**
     * @return bool
     */
    public function isProxyHttp(): bool
    {
        return $this->proxyHttp;
    }

    /**
     * @return string
     */
    public function getProxyHttpHost(): string
    {
        return $this->proxyHttpHost;
    }

    /**
     * @return string
     */
    public function getProxyHttpPort(): string
    {
        return $this->proxyHttpPort;
    }

    /**
     * @return string
     */
    public function getProxyHttpUsername(): string
    {
        return $this->proxyHttpUsername;
    }

    /**
     * @return string
     */
    public function getProxyHttpPassword(): string
    {
        return $this->proxyHttpPassword;
    }

    /**
     * @return bool
     */
    public function isProxySocks5(): bool
    {
        return $this->proxySocks5;
    }

    /**
     * @return string
     */
    public function getProxySocks5Host(): string
    {
        return $this->proxySocks5Host;
    }

    /**
     * @return string
     */
    public function getProxySocks5Port(): string
    {
        return $this->proxySocks5Port;
    }

    /**
     * @return string
     */
    public function getProxySocks5Username(): string
    {
        return $this->proxySocks5Username;
    }

    /**
     * @return string
     */
    public function getProxySocks5Password(): string
    {
        return $this->proxySocks5Password;
    }
}